<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${gift == null ? '发布' : '编辑'}礼包</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
    <style type="text/css">
        .condition .layui-form-radio {
            display: block !important;
        }

        .text-place {
            padding-left: 30px;
            color: #aaa;
        }

        .layui-form-label {
            width: 120px !important;
        }

        .layui-input-block {
            margin-left: 150px !important;
        }

        .xy {
            width: calc(100% - 190px);
            resize: none;
            min-height: 55px;
            float: left;
            margin-right: 10px;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
                <form id="myForm" class="layui-form mt20" method="post" action="${ctx}/gift/gift/save.do">
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用场景<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <input type="radio" name="type" lay-filter="type" lay-verify="type" value="ZC_ACTIVITY"
                                   title="众筹" ${empty gift.type || gift.type == 'ZC_ACTIVITY' ? 'checked="checked"' : ''} />
                            <input type="radio" name="type" lay-filter="type" lay-verify="type" value="ACTIVITY"
                                   title="活动" ${gift.type == 'ACTIVITY' ? 'checked="checked"' : ''} />
                            <input type="radio" name="type" lay-filter="type" lay-verify="type" value="ARTICLE"
                                   title="文章" ${gift.type == 'ARTICLE' ? 'checked="checked"' : ''} />
                            <input type="radio" name="type" lay-filter="type" lay-verify="type" value="GOODS"
                                   title="玩法" ${gift.type == 'GOODS' ? 'checked="checked"' : ''} disabled />
                        </div>
                    </div>
                    <div class="layui-form-item condition zcActivityDiv" ${empty gift.type || gift.type == 'ZC_ACTIVITY' ? '' : 'style="display:none"'}>
                        <label class="layui-form-label">发放对象<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <input type="radio" name="condition" lay-filter="condition" lay-verify="condition" value="ZC_SUPPORT"
                                   title="支持者礼包" ${gift.condition == 'ZC_SUPPORT' ? 'checked="checked"' : ''} />
                            <span class="text-place">适用于支持了众筹的人员</span>

                            <input type="radio" name="condition" lay-filter="condition" lay-verify="condition" value="ZC_APPLY"
                                   title="众筹参与礼包" ${gift.condition == 'ZC_APPLY' ? 'checked="checked"' : ''} />
                            <span class="text-place">适用于报名参加了众筹的人员</span>

                            <input type="radio" name="condition" lay-filter="condition" lay-verify="condition" value="ZC_ING"
                                   title="众筹鼓励礼包" ${gift.condition == 'ZC_ING' ? 'checked="checked"' : ''} />
                            <span class="text-place">适用于众筹进行中的人员</span>

                            <input type="radio" name="condition" lay-filter="condition" lay-verify="condition" value="ZC_SUCCESS"
                                   title="众筹成功礼包" ${gift.condition == 'ZC_SUCCESS' ? 'checked="checked"' : ''} />
                            <span class="text-place">适用于众筹成功的人员</span>
                        </div>
                    </div>
                    <div class="layui-form-item condition activityDiv" ${gift.type == 'ACTIVITY' ? '' : 'style="display:none"'}>
                        <label class="layui-form-label">发放对象<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">

                        </div>
                    </div>
                    <div class="layui-form-item condition articleDiv" ${gift.type == 'ARTICLE' ? '' : 'style="display:none"'}>
                        <label class="layui-form-label">发放对象<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">

                        </div>
                    </div>
                    <div class="layui-form-item condition goodsDiv" ${gift.type == 'GOODS' ? '' : 'style="display:none"'}>
                        <label class="layui-form-label">发放对象<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">

                        </div>
                    </div>
                    <div class="layui-form-item conditionParams support" ${gift.condition == 'ZC_SUPPORT' || gift.condition == 'ZC_ING' ? '' : 'style="display: none;"'}>
                        <div class="layui-inline">
                            <label class="layui-form-label">发放条件<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline" style="width: 120px">
                                <select name="restraint">
                                    <option value="{money}"><c:if test="${gift.condition == 'ZC_SUPPORT'}">支持</c:if><c:if test="${gift.condition == 'ZC_ING'}">众筹</c:if>金额</option>
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width: 120px">
                                <select name="symbol" lay-verify="symbol">
                                    <option value="">请选择</option>
                                    <option value=">" ${fn:indexOf(gift.conditionParams, '>') != -1 ? 'selected' : ''}>大于</option>
                                    <option value=">=" ${fn:indexOf(gift.conditionParams, '>=') != -1 ? 'selected' : ''}>大于等于</option>
                                    <option value="<" ${fn:indexOf(gift.conditionParams, '<') != -1 ? 'selected' : ''}>小于</option>
                                    <option value="<=" ${fn:indexOf(gift.conditionParams, '<=') != -1 ? 'selected' : ''}>小于等于</option>
                                    <option value="==" ${fn:indexOf(gift.conditionParams, '==') != -1 ? 'selected' : ''}>等于</option>
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width: 120px">
                                <input type="text" name="conditionParams" lay-verify="conditionParams" class="layui-input"
                                       value="${fn:substring(gift.conditionParams, gift.conditionParams.lastIndexOf(' ') + 1, gift.conditionParams.length())}">
                            </div>
                            <div class="layui-form-mid layui-word-aux">元</div>
                        </div>
                    </div>
                    <%--<div class="layui-form-item conditionParams support" ${gift.condition == 'ZC_SUPPORT' || gift.condition == 'ZC_ING' ? '' : 'style="display: none;"'}>
                        <div class="layui-inline">
                            <label class="layui-form-label">发放条件<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline" style="width: 300px">
                                <input type="text" name="conditionParams" lay-verify="conditionParams" class="layui-input" value="${gift.conditionParams}">
                            </div>
                            <div class="layui-form-mid layui-word-aux">money表示金额</div>
                        </div>
                    </div>--%>
                    <div class="layui-form-item">
                        <label class="layui-form-label">礼包类型<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <input type="radio" name="model" lay-verify="model" lay-filter="model" value="1"
                                   title="虚拟" ${gift.model == 1 ? 'checked="checked"' : ''} ${gift.salesNum > 0 ? 'disabled="disabled"' : ''} />
                            <input type="radio" name="model" lay-verify="model" lay-filter="model" value="2"
                                   title="实物" ${gift.model == 2 ? 'checked="checked"' : ''} ${gift.salesNum > 0 ? 'disabled="disabled"' : ''} />
                            <input type="radio" name="model" lay-verify="model" lay-filter="model" value="3"
                                   title="广告链接" ${gift.model == 3 ? 'checked="checked"' : ''} ${gift.salesNum > 0 ? 'disabled="disabled"' : ''} />
                        </div>
                    </div>
                    <div class="layui-form-item couponDiv" ${gift.model == 1 ? '' : 'style="display:none"'}>
                        <div class="layui-inline">
                            <label class="layui-form-label">券&emsp;&emsp;码<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline" style="margin-right: 120px;">
                                <input type="hidden" name="couponIds" lay-verify="couponId" value="${gift.couponIds}" id="couponId"/>
                                <input type="text" class="layui-input" readonly="readonly" id="couponName"
                                       style="width: 300px;" value="${gift.couponNames}"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn layui-btn-danger" onclick="selectCoupon()" type="button">选择券</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item advertiseDiv" ${gift.model == 3 ? '' : 'style="display:none"'}>
                        <div class="layui-inline">
                            <label class="layui-form-label">广告链接<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline">
                                <input type="text" name="advertiseUrl" lay-verify="advertiseUrl" class="layui-input"
                                       value="${gift.advertiseUrl}" style="width: 300px;">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">业务项目</label>
                            <div class="layui-input-inline" style="margin-right: 120px;">
                                <input type="hidden" name="targetIds" lay-verify="targetId" value="${gift.targetIds}" id="targetId"/>
                                <input type="text" class="layui-input" readonly="readonly" id="targetName"
                                       style="width: 300px;" value="${gift.targetNames}"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn layui-btn-danger" onclick="selectProject()" type="button">
                                    选择业务项目
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">礼包名称<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" lay-verify="title" placeholder="礼包名称" class="layui-input" value="${gift.name}" style="width: 300px;">
                                <input type="hidden" name="id" value="${gift.id}"/>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图&emsp;&emsp;片<span class="f-verify-red">*</span></label>
                        <div class="cover-content">
                            <input type="hidden" name="pic" id="pic" lay-verify="pic" value="${gift.pic}"/>
                            <c:if test="${gift == null || empty gift.pic}">
                                <span id="cover-img" class="cover-img" style="background-image:url(${ctx}/image/posterImg.png)"></span>
                            </c:if>
                            <c:if test="${gift != null && not empty gift.pic}">
                                <span id="cover-img" class="cover-img" style="background-image:url('${gift.pic}')"></span>
                            </c:if>
                            <a class="layui-btn layui-btn-danger" id="sel_pic_img">+添加图片</a>
                            <div class="form-word-aux">建议尺寸：800x450</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">礼包价值<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline">
                                <input type="text" name="price" lay-verify="price" placeholder="￥" class="layui-input" value="${gift.price}"/>
                            </div>
                            <div class="layui-form-mid layui-word-aux">元</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">发放数量<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline">
                                <input type="text" name="stock" lay-verify="stock" class="layui-input" value="${gift.stock}"/>
                            </div>
                            <div class="layui-form-mid layui-word-aux">个</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">发放时间<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="startDate" lay-verify="startDate" placeholder="开始时间" id="startTime" readonly
                                       value='<fmt:formatDate value="${gift.startTime}" pattern="yyyy-MM-dd" />'
                                />
                            </div>
                            <div class="layui-input-inline" style="width: 10px; margin-top: 8px; margin-left: 2px;">至
                            </div>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="endDate" lay-verify="endDate" placeholder="结束时间" id="endTime" readonly
                                       value='<fmt:formatDate value="${gift.endTime}" pattern="yyyy-MM-dd" />'
                                />
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">基本说明<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <textarea name="remarks" maxlength="80" placeholder="一句话简介" lay-verify="remarks" class="layui-textarea xy">${gift.remarks}</textarea>
                            <div class="layui-form-mid layui-word-aux">最多80字</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">详细说明<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <textarea name="explain" maxlength="400" placeholder="使用说明" lay-verify="explain" class="layui-textarea">${gift.explain}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
                            <a href="${ctx}/gift/gift/list.do" class="layui-btn layui-btn-primary">取消</a>
                        </div>
                    </div>
                </form>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/form_cache.js"></script>
<script>
    var form, formcache;
    var giftTypeValue = '${gift.type}' || 'ZC_ACTIVITY', giftConditionValue = '${gift.condition}' || 'ZC_SUPPORT',
        giftModelValue = null;
    $(function () {
        layui.use(['form', 'laydate'], function () {
            form = layui.form, laydate = layui.laydate;
            form.render('radio');
            form.render('select');

            // 查询开始日期
            var start = {
                elem: '#startTime'
            };

            var end = {
                elem: '#endTime'
            };
            laydate.render(start);
            laydate.render(end);

            form.on('radio(type)', function (data) {
                giftTypeValue = data.value;
                $(".condition").hide();
                if (giftTypeValue == 'ZC_ACTIVITY') {
                    $(".zcActivityDiv").show();
                } else if (giftTypeValue == 'ACTIVITY') {
                    $(".activityDiv").show();
                } else if (giftTypeValue == 'GOODS') {
                    $(".goodsDiv").show();
                } else if (giftTypeValue == 'ARTICLE') {
                    $(".articleDiv").show();
                }
                $(".conditionParams").hide();
            });

            form.on('radio(condition)', function (data) {
                giftConditionValue = data.value;
                if (giftConditionValue == 'ZC_SUPPORT' || giftConditionValue == 'ZC_ING') {
                    if (giftConditionValue == 'ZC_SUPPORT') {
                        $("[name=restraint] option:eq(0)").text("支持金额");
                    } else if (giftConditionValue == 'ZC_ING') {
                        $("[name=restraint] option:eq(0)").text("众筹金额");
                    }
                    form.render('select');
                    $(".conditionParams").show();
                } else {
                    $(".conditionParams").hide();
                }
            });

            form.on('radio(model)', function (data) {
                giftModelValue = data.value;
                if (giftModelValue == 1) {
                    $(".couponDiv").show();
                    $(".advertiseDiv").hide();
                } else if (giftModelValue == 3) {
                    $(".advertiseDiv").show();
                    $(".couponDiv").hide();
                } else {
                    $(".advertiseDiv").hide();
                    $(".couponDiv").hide();
                }
            });

            //自定义验证规则
            form.verify({
                type: function (value) {
                    var value1 = $("input[name=type]:checked").val();
                    if (value1 == null) {
                        return "请选择礼包应用场景";
                    }
                },
                condition: function (value) {
                    var container = null;
                    if (giftTypeValue == 'ZC_ACTIVITY') {
                        container = ".zcActivityDiv";
                    } else if (giftTypeValue == 'ACTIVITY') {
                        container = ".activityDiv";
                    } else if (giftTypeValue == 'ARTICLE') {
                        container = ".articleDiv";
                    } else if (giftTypeValue == 'GOODS') {
                        container = ".goodsDiv";
                    }
                    var value1 = $(container).find("input[name=condition]:checked").val();
                    if (value1 == null) {
                        return "请选择礼包发放对象";
                    }
                },
                symbol : function (value) {
                    if (giftConditionValue == 'ZC_SUPPORT' || giftConditionValue == 'ZC_ING') {
                        if (value == "") {
                            return "请选择礼包发放条件";
                        }
                    }
                },
                conditionParams: function (value) {
                    if (giftConditionValue == 'ZC_SUPPORT' || giftConditionValue == 'ZC_ING') {
                        if (value == "") {
                            return "请输入礼包发放条件";
                        } else if (value == "") {
                            return "请输入礼包发放条件参数";
                        } else if (!util.checkFloat(value)) {
                            return "请输入礼包发放条件参数";
                        }
                    }
                },
                model: function (value) {
                    var value1 = $("input[name=model]:checked").val();
                    if (value1 == null) {
                        return "请选择礼包类型";
                    }
                },
                advertiseUrl: function (value) {
                    if (giftModelValue == 3 && value == "") {
                        return "请填写广告链接";
                    }
                },
                couponId: function (value) {
                    if (giftModelValue == 1 && value == "") {
                        return "请选择票券";
                    }
                },
                targetId: function (value) {
                    /*if (value == "") {
                        return "请选择业务项目";
                    }*/
                },
                title: function (value) {
                    if (value == "") {
                        return '请输入礼包名称';
                    }
                },
                pic: function (value) {
                    if (value == "") {
                        return "请上传礼包图片";
                    }
                },
                price: function (value) {
                    if (value == "") {
                        return "请输入礼包价值";
                    } else if (!util.checkFloat(value)) {
                        return "请输入正确的金额";
                    }
                },
                stock: function (value) {
                    if (value == "") {
                        return "请输入礼包发放数量";
                    } else if (!util.checkNumber(value)) {
                        return "请输入正确的数字";
                    } else if (parseInt(value) == 0) {
                        return "请输入大于0的数字";
                    } else if (parseInt(value) < parseInt('${gift.salesNum}')) {
                        return "请输入大于礼包领取数量的数字";
                    }

                    if (giftModelValue == 1) {
                        var stock = $("#couponId").data("stock");
                        if (parseInt(value) > parseInt(stock)) {
                            $("[name=stock]").val(stock);
                            return "礼包发放数量不得大于票券库存数量";
                        }
                    }
                },
                startDate: function (value) {
                    if (value == "") {
                        return "请设置礼包有效期开始时间";
                    }
                },
                endDate: function (value) {
                    if (value == "") {
                        return "请设置礼包有效期结束时间";
                    }
                    var startDate = $("[name=startDate]").val();
                    var endDate = $("[name=endDate]").val();

                    if (startDate >= endDate) {
                        return "开始时间应该早于结束时间";
                    }
                },
                remarks : function (value) {
                    if (value == "") {
                        return "请输入礼包基本说明";
                    }
                },
                explain : function (value) {
                    if (value == "") {
                        return "请输入礼包详细说明";
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                <%--var targetId = $("#targetId").val();--%>
                <%--if (targetId != "") {--%>
                    <%--var giftId = '${gift.id}';--%>
                    <%--var type = $("[name=type]:checked").val();--%>
                    <%--var condition = $("[name=condition]:checked").val();--%>
                    <%--var result = checkGiftType(type, condition, targetId, giftId);--%>
                    <%--if (result) {--%>
                        <%--submitForm(data);--%>
                    <%--} else {--%>
                        <%--layer.msg("业务项目已经有了这个条件的礼包，请重新选择条件");--%>
                        <%--return false;--%>
                    <%--}--%>
                <%--} else {--%>

                <%--}--%>
                submitForm(data);
            });
            if(!'${gift.id}'){
                formcache = new fCache({
                    fCacheKey: 'form_cache_gift',//暂存的key
                    cacheCallback: loadCacheData,//获取到缓存后加载的方法
                    getFormData: getFormData
                }).init();
            }
        });

        function getFormData() {
            var formData = util.serializeForm($('#myForm').serializeArray());
            return formData;
        }

        function submitForm(data) {
            txz.submitObject(data.elem, function (callBack) {
                var formData = getFormData();
                var action = $("#myForm").attr("action");
                txz.ajaxRequest({
                    method: 'post',
                    url: action,
                    saveCache: true,
                    cacheObj: formcache,
                    params: formData,
                    callBack: function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("提交成功", function () {
                                location.href = "${ctx}/gift/gift/list.do";
                            });
                        } else {
                            util.layerMsgError(res.description || '提交失败');
                        }
                    }
                });
            });
        }

        //此方法用于加载缓存数据
        function loadCacheData(cacheData) {
            //加载封面图
            if (cacheData['pic']) {
                $('#cover-img').css('background-image', 'url(' + cacheData['pic'] + ')');
            }
            form.render();
        }

        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：800x450',
                type: '<%=TargetType.GIFT.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        })
    });

    // 选择业务项目
    function selectProject() {
        var url = '${ctx}/activity/activity/selectZcActivity.do';
        if (giftTypeValue == 'ZC_ACTIVITY') {
            url = '${ctx}/activity/activity/selectZcActivity.do';
        } else if (giftTypeValue == 'ACTIVITY') {
            url = '${ctx}/activity/activity/selectActivity.do';
        } else if (giftTypeValue == 'GOODS') {

        } else if (giftTypeValue == 'ARTICLE') {
            url = '${ctx}/article/article/selectArticle.do';
        }

        function cb($jquery) {
            var targetId = $($jquery.find("#targetId")).val();
            var targetName = $($jquery.find("#targetName")).val();
            $("#targetId").val(targetId);
            $("#targetName").val(targetName);
        }

        openDialog('选择业务项目', url, '800px', '570px', cb);
    }

    // 选择票券
    function selectCoupon() {
        function cb($jquery) {
            var couponId = $($jquery.find("#couponId")).val();
            var couponName = $($jquery.find("#couponName")).val();
            var stock = $($jquery.find("#stock")).val();
            $("#couponId").val(couponId);
            $("#couponName").val(couponName);
            $("[name=stock]").val(stock);
            $("#couponId").attr("data-stock", stock);
        }

        openDialog('选择券', '${ctx}/coupon/coupon/selectCoupon.do?couponId=${gift.couponIds}&giftId=${gift.id}', '800px', '570px', cb);
    }

    function openDialog(title, url, width, height, cb, target) {
        layer.open({
            type: 2,
            area: [width, height],
            title: title,
            maxmin: true, //开启最大化最小化按钮
            content: url,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if (target) {
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                } else {
                    top_iframe = '_parent';//获取当前active的tab的iframe
                }
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if (iframeWin.contentWindow.doSubmit()) {
                    cb(iframeWin.contentWindow.$);

                    setTimeout(function () {
                        top.layer.close(index);
                    }, 100);//延时0.1秒，对应360 7.1版本bug
                }

            },
            cancel: function (index) {
            }
        });
    }

    /**
     * 检查礼包类型及触发条件唯一性
     * @param type 礼包类型
     * @param condition 触发条件
     * @param targetId 众筹项目
     * @param giftId 礼包id
     * @returns {boolean} true/false
     */
    function checkGiftType(type, condition, targetId, giftId) {
        var isRepeat = false;
        $.ajax({
            type: 'POST',
            async: false, // 使用同步的方法
            data: {
                type: type,
                condition: condition,
                targetId: targetId,
                giftId: giftId
            },
            dataType: 'json',
            success: function (result) {
                isRepeat = result;
            },
            url: '${ctx}/gift/gift/checkGiftUnique.do'
        });
        return isRepeat;
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '礼包管理',
            href:'${ctx}/gift/gift/list.do',
        },{
            name: '${gift == null ? '发布' : '编辑'}礼包',
            curr: true
        }],
        btns:[{
            type:'back'
        }]
    });
</script>
</body>
</html>